package com.yanqu.road.logic.pb;

import com.yanqu.road.entity.enums.eMarriageStatusType;
import com.yanqu.road.entity.marriage.MarriageInfo;
import com.yanqu.road.entity.marriage.MarriageRecord;
import com.yanqu.road.entity.player.UserMarriageData;
import com.yanqu.road.pb.marriage.CrossMarriageProto;
import com.yanqu.road.pb.marriage.MarriageProto;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;

public class MarriagePb {

    public static  MarriageInfo parseMarriageInfo(MarriageProto.MarriageApplyTempMsg tempMsg) {
        if(null == tempMsg){
            return null;
        }
        MarriageInfo data = new MarriageInfo();
        data.setStatus(eMarriageStatusType.parse(tempMsg.getState()));
        data.setUserId(tempMsg.getUserId());
        data.setUserNickName(tempMsg.getUserNickName());
        data.setChildUid(tempMsg.getChildUid());
        data.setChildTalent(tempMsg.getChildTalent());
        data.setChildOccupation(tempMsg.getChildOccupation());
        data.setChildName(tempMsg.getChildName());
        data.setChildSex(tempMsg.getChildSex());
        data.setChildHeadIcon(tempMsg.getChildHeadIcon());
        data.setPublishTime(tempMsg.getPublishTime());
        data.setAppointUserId(tempMsg.getAppointUserId());
        data.setChildAdultTime(tempMsg.getChildAdultTime());
        data.setChildOccupationId(tempMsg.getChildOccupationId());
        data.setChildEarnSpeed(new BigInteger(tempMsg.getChildEarnSpeed()));
        data.setReward(PropertyHelper.parseStringToProperty(tempMsg.getReward()));
        data.setChildOccupationAddition(tempMsg.getChildOccupationAddition());
        data.setMotherBeautyId(tempMsg.getMotherId());
        data.setTwins(tempMsg.getIsTwins());
        data.setLimitEarnSpeed(new BigInteger(tempMsg.getLimitEarnSpeed()));
        data.setServerId(tempMsg.getServerId());
        data.setPartnerServerId(tempMsg.getPartnerServerId());
        return data;
    }

    public static  MarriageProto.MarriageApplyTempMsg.Builder parseMarriageApplyTempMsg(MarriageInfo marriageInfo) {
        if(null == marriageInfo){
            return null;
        }
        MarriageProto.MarriageApplyTempMsg.Builder msg = MarriageProto.MarriageApplyTempMsg.newBuilder();
        msg.setState(marriageInfo.getStatus().getValue());
        msg.setUserId(marriageInfo.getUserId());
        msg.setUserNickName(marriageInfo.getUserNickName());
        msg.setChildUid(marriageInfo.getChildUid());
        msg.setChildTalent(marriageInfo.getChildTalent());
        msg.setChildOccupation(marriageInfo.getChildOccupation());
        msg.setChildName(marriageInfo.getChildName());
        msg.setChildSex(marriageInfo.getChildSex());
        msg.setChildHeadIcon(marriageInfo.getChildHeadIcon());
        msg.setPublishTime(marriageInfo.getPublishTime());
        msg.setAppointUserId(marriageInfo.getAppointUserId());
        msg.setChildAdultTime(marriageInfo.getChildAdultTime());
        msg.setChildOccupationId(marriageInfo.getChildOccupationId());
        msg.setChildEarnSpeed(marriageInfo.getChildEarnSpeed().toString());
        msg.setReward(PropertyHelper.parsePropertyToString(marriageInfo.getReward()));
        msg.setChildOccupationAddition(marriageInfo.getChildOccupationAddition());
        msg.setMotherId(marriageInfo.getMotherBeautyId());
        msg.setIsTwins(marriageInfo.isTwins());
        msg.setLimitEarnSpeed(marriageInfo.getLimitEarnSpeed().toString());
        msg.setServerId(marriageInfo.getServerId());
        msg.setPartnerServerId(marriageInfo.getPartnerServerId());
        msg.setCurioAddition(marriageInfo.getCurioAddition());
        return msg;
    }

    public static MarriageProto.MarriageApplyListMsg.Builder parseMarriageApplyListMsg(List<MarriageInfo> applyList) {
        MarriageProto.MarriageApplyListMsg.Builder listMsg = MarriageProto.MarriageApplyListMsg.newBuilder();
        if (null != applyList) {
            for (MarriageInfo apply : applyList) {
                MarriageProto.MarriageApplyTempMsg.Builder msg = parseMarriageApplyTempMsg(apply);
                if(null != msg){
                    listMsg.addDataList(msg);
                }
            }
        }
        return listMsg;
    }

    public static  MarriageProto.MarriageRecordTempMsg.Builder parseMarriageRecordTempMsg(MarriageRecord marriageRecord) {
        if(null == marriageRecord){
            return null;
        }
        MarriageProto.MarriageRecordTempMsg.Builder msg = MarriageProto.MarriageRecordTempMsg.newBuilder();
        msg.setUserId(marriageRecord.getUserId());
        msg.setUserNickName(marriageRecord.getUserNickName());
        msg.setChildUid(marriageRecord.getChildUid());
        msg.setChildTalent(marriageRecord.getChildTalent());
        msg.setChildOccupation(marriageRecord.getChildOccupation());
        msg.setChildName(marriageRecord.getChildName());
        msg.setChildSex(marriageRecord.getChildSex());
        msg.setChildHeadIcon(marriageRecord.getChildHeadIcon());
        msg.setPublishTime(marriageRecord.getPublishTime());
        msg.setPartnerUserId(marriageRecord.getPartnerUserId());
        msg.setPartnerNickName(marriageRecord.getPartnerNickName());
        msg.setPartnerChildTalent(marriageRecord.getPartnerChildTalent());
        msg.setPartnerChildSex(marriageRecord.getPartnerChildSex());
        msg.setPartnerChildOccupation(marriageRecord.getPartnerChildOccupation());
        msg.setPartnerChildName(marriageRecord.getPartnerChildName());
        msg.setPartnerChildHeadIcon(marriageRecord.getPartnerChildHeadIcon());
        msg.setAppointUserId(marriageRecord.getAppointUserId());
        msg.setMarriageTime(marriageRecord.getMarriageTime());
        msg.setChildAdultTime(marriageRecord.getChildAdultTime());
        msg.setChildOccupationId(marriageRecord.getChildOccupationId());
        msg.setChildEarnSpeed(marriageRecord.getChildEarnSpeed().toString());
        msg.setReward(PropertyHelper.parsePropertyToString(marriageRecord.getReward()));
        msg.setPartnerChildOccupationId(marriageRecord.getPartnerChildOccupationId());
        msg.setPartnerChildEarnSpeed(marriageRecord.getPartnerChildEarnSpeed().toString());
        msg.setPartnerReward(PropertyHelper.parsePropertyToString(marriageRecord.getPartnerReward()));
        msg.setTotalChildEarnSpeed(marriageRecord.getTotalChildEarnSpeed().toString());
        msg.setMotherId(marriageRecord.getMotherId());
        msg.setPartnerMotherId(marriageRecord.getPartnerMotherId());
        msg.setChildIsTwins(marriageRecord.isTwins());
        msg.setPartnerIsTwins(marriageRecord.isPartnerTwins());
        msg.setServerId(marriageRecord.getServerId());
        msg.setPartnerServerId(marriageRecord.getPartnerServerId());
        return msg;
    }

    public static MarriageProto.MarriageRecordListMsg.Builder parseMarriageRecordListMsg(List<MarriageRecord> marriageRecordList) {
        MarriageProto.MarriageRecordListMsg.Builder listMsg = MarriageProto.MarriageRecordListMsg.newBuilder();
        if (null != marriageRecordList) {
            for (MarriageRecord marriageRecord : marriageRecordList) {
                MarriageProto.MarriageRecordTempMsg.Builder msg = parseMarriageRecordTempMsg(marriageRecord);
                if(null != msg){
                    listMsg.addDataList(msg);
                }
            }
        }
        return listMsg;
    }

    public static MarriageProto.MarriageUserDataMsg.Builder parseMarriageUserDataMsg(UserMarriageData userMarriageData) {
        if(null == userMarriageData){
            return null;
        }
        MarriageProto.MarriageUserDataMsg.Builder msg = MarriageProto.MarriageUserDataMsg.newBuilder();
        msg.setIsAcceptAppoint(userMarriageData.isAcceptAppoint());
        msg.setServerApplyRefreshTimes(userMarriageData.getServerApplyRefreshTimes());
        msg.setBuyServerApplyRefreshTimes(userMarriageData.getBuyServerApplyRefreshTimes());
        msg.setTotalMarriageTimes(userMarriageData.getTotalMarriageTimes());
        msg.setTotalLonelyCount(userMarriageData.getTotalLonelyCount());
        msg.setCrossApplyRefreshTimes(userMarriageData.getCrossServerApplyRefreshTimes());
        msg.setBuyCrossApplyRefreshTimes(userMarriageData.getBuyCrossServerApplyRefreshTimes());
        msg.setIsAcceptCrossAppoint(userMarriageData.isAcceptCrossAppoint());
        return msg;
    }

    public static MarriageProto.MarriageRefuseNotifyMsg.Builder parseMarriageRefuseNotifyMsg(List<String> childUidList){
        MarriageProto.MarriageRefuseNotifyMsg.Builder listMsg = MarriageProto.MarriageRefuseNotifyMsg.newBuilder();
        for(String childUid : childUidList){
            listMsg.addChildUid(childUid);
        }
        return listMsg;
    }

    public static CrossMarriageProto.CrossMarriageRefuseNotifyListMsg.Builder parseCrossMarriageRefuseNotifyListMsg(Map<Long, List<String>> dataMap){
        CrossMarriageProto.CrossMarriageRefuseNotifyListMsg.Builder listMsg = CrossMarriageProto.CrossMarriageRefuseNotifyListMsg.newBuilder();
        for(Map.Entry<Long, List<String>> dataEntry : dataMap.entrySet()){
            CrossMarriageProto.CrossMarriageRefuseNotifyTempMsg.Builder msg = parseCrossMarriageRefuseNotifyTempMsg(dataEntry.getKey(), dataEntry.getValue());
            listMsg.addDataList(msg);
        }
        return listMsg;
    }

    public static CrossMarriageProto.CrossMarriageRefuseNotifyTempMsg.Builder parseCrossMarriageRefuseNotifyTempMsg(long userId, List<String> childList){
        CrossMarriageProto.CrossMarriageRefuseNotifyTempMsg.Builder msg = CrossMarriageProto.CrossMarriageRefuseNotifyTempMsg.newBuilder();
        msg.setUserId(userId);
        msg.addAllChildUid(childList);
        return msg;
    }

    /**
     * 子嗣对象复制赋值
     *
     * @param destMarriage
     * @param srcMarriage
     */
    public static void cloneMarriage(MarriageInfo destMarriage, MarriageInfo srcMarriage) {
        destMarriage.setUserId(srcMarriage.getUserId());
        destMarriage.setUserNickName(srcMarriage.getUserNickName());
        destMarriage.setStatus(srcMarriage.getStatus());
        destMarriage.setChildUid(srcMarriage.getChildUid());
        destMarriage.setChildTalent(srcMarriage.getChildTalent());
        destMarriage.setChildName(srcMarriage.getChildName());
        destMarriage.setChildSex(srcMarriage.getChildSex());
        destMarriage.setChildOccupation(srcMarriage.getChildOccupation());
        destMarriage.setChildHeadIcon(srcMarriage.getChildHeadIcon());
        destMarriage.setChildAdultTime(srcMarriage.getChildAdultTime());
        destMarriage.setPublishTime(srcMarriage.getPublishTime());
        destMarriage.setAppointUserId(srcMarriage.getAppointUserId());
        destMarriage.setReward(srcMarriage.getReward());
        destMarriage.setMotherBeautyId(srcMarriage.getMotherBeautyId());
        destMarriage.setChildOccupationId(srcMarriage.getChildOccupationId());
        destMarriage.setChildEarnSpeed(srcMarriage.getChildEarnSpeed());
        destMarriage.setChildOccupationAddition(srcMarriage.getChildOccupationAddition());
        destMarriage.setTwins(srcMarriage.isTwins());
        destMarriage.setLimitEarnSpeed(srcMarriage.getLimitEarnSpeed());
        destMarriage.setServerId(srcMarriage.getServerId());
        destMarriage.setPartnerServerId(srcMarriage.getPartnerServerId());
        destMarriage.setMarriageConsume(srcMarriage.getMarriageConsume());
    }
}
